package com.example.desinger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.desinger.common.R;
import com.example.desinger.entity.Classroom;
import com.example.desinger.mapper.ClassRoomMapper;
import com.example.desinger.service.ClassRoomService;
import org.springframework.stereotype.Service;

@Service
public class ClassRoomServiceImpl extends ServiceImpl<ClassRoomMapper, Classroom> implements ClassRoomService  {
    @Override
    public R<String> addClass(String nickname) {
        LambdaQueryWrapper<Classroom> lambdaQueryWrapper =
                new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Classroom::getNickname,nickname);
        Classroom one = getOne(lambdaQueryWrapper);
        System.out.println(""+one);

        if (one==null){
            Classroom classroom1= new Classroom();
            classroom1.setNickname(nickname);
            System.out.println("classrom:"+classroom1);
            save(classroom1);
           return R.success("添加成功");
        }

        return R.error("该班级已经被添加过了，不要重复添加");
    }
}
